<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : "{{ urlfor "ArchivesController.DataGrid"}}"
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var params = checkQueryTableData(aoData)
			$('#search_key').val() ? params.Filter = $('#search_key').val() : ''
			$.post(sSource, JSON.stringify(params),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
            /*{"mDataProp" : "Number", "bSortable": false}*/
			{"mDataProp" : "Realname", "bSortable": false}
            ,{"data" : "Mobile","bSortable": false}
			,{"mDataProp" : "Sex", "bSortable": false}
			,{"mDataProp" : "Age", "bSortable": false}
			,{"mDataProp" : "Birthday", "bSortable": false}
			,{"mDataProp" : "Address", "bSortable": false}
			,{"mDataProp": "CreatedAt", render:function(data, type, full, meta) {
				return timetrans(data);	
			}} 
			,{   
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"15%",
				"render": function ( data, type, full, meta ) { 
					btns = '<div class="tpl-table-black-operation">';
					//btns += '&nbsp;<a href="/outpatient/view/'+ full.Id +'" class="am-btn am-btn-success am-btn-xs actionArchives">查看</a>';
					btns += '&nbsp;<a href="javascript:;" onclick="actionArchives('+ full.Id +');return false;" class="am-btn am-btn-secondary am-btn-xs">编辑</a>';
					btns += '&nbsp;<a href="javascript:;" class="am-btn am-btn-danger am-btn-xs" onclick="delArchives('+ full.Id +');return false;">删除</a></div>';
					return btns;  
				}  
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	function dialogReback() {
		$("#dataTables").dataTable().fnDraw(false);
	}
	$("#searchsubmit").bind("click", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
	});

    $(window).keydown(function (event) {
        if(event.keyCode==13){
            var value = $('#search_key').val();
            if(value != '') {
                $("#searchsubmit").click();
            }
        }
    });
	function actionArchives(id) {
		layer.open({
        	type: 2
			, title: '<i class="fa fa-cog"></i>&nbsp;新增档案'
			, shadeClose: true
			, shade: 0.2
			, id: 'search_archives_dialog'
			, area: ['1000px', "540px"]
			, content: ['{{ urlfor "ArchivesController.Edit"}}/'+id]
			, anim: 1 //动画类型
		});
		return false;
	}
	

	function delArchives(id) {
		layer.confirm('确定要删除所选记录吗？删除后不可恢复！', function(index){
			$.post('{{ urlfor "ArchivesController.Delete"}}', {id:id}, function(res){
				if(res.code == 1) {
					layer.msg(res.msg)
				} else {
					tables.ajax.reload();
				}
				layer.close(index);
			}, 'json');
		});
	}
</script>
